<!DOCTYPE html>
<html>

<head>
  <meta charset="utf-8" />
  <meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=no" />
  <meta name="misapplication-tap-highlight" content="no" />
  <meta name="HandheldFriendly" content="true" />
  <meta name="MobileOptimized" content="320" />
  <link rel="stylesheet" href="cs.css">
  <title>QmSdk-Map</title>
</head>

<body>
  <div class="inputItem"><span class="label">导航App：</span>
    <select class="select" name="type" id="type">
      <!-- <option value="">--请选择--</option> -->
      <option value="1">高德</option>
      <option value="2">百度</option>
      <option value="3">腾讯</option>
    </select>
  </div>
  <div class="button" onclick="navigationto()">
    调用导航
  </div>

  <div class="button" onclick="getLocation()">
    获取位置信息
  </div>

  <div class="info">
  </div>

  <script src="../qmsdk.js"></script>
  <script>
    let that = this;
    let infoBox = document.querySelector(".info");
    let currentLocation = {};

    function navigationto() {
      let p = document.createElement("p");
      window.qmSdk.navigationto({
        type: document.querySelector("#type").value, // 坐标类型“1”:高德,“2”:百度,“3”:腾讯
        longitude: 113.441572, // 经度
        latitude: 23.168447, // 纬度
        address: "广州市齐明软件科技有限公司", // 目的地描述
        success: () => {
          p.innerText = "打开地图App成功";
          infoBox.appendChild(p);
        },
        fail: err => {
          console.log(err);
          p.innerText = err;
          infoBox.appendChild(p);
        }
      })
    }

    function getLocation() {
      return new Promise((resolve, reject) => {
        window.qmSdk.getLocation({
          success: function (res) {
            console.log("success -->", res);
            currentLocation = res;
            let p = document.createElement("p");
            p.appendChild(document.createTextNode("您的位置：" + res.addresses));
            p.appendChild(document.createTextNode("经度：" + res.coords.longitude));
            p.appendChild(document.createTextNode("纬度：" + res.coords.latitude));
            infoBox.appendChild(p);
            resolve();
          }
        })
      })
    }

  </script>
</body>

</html>
